package com.upcode.weighing.util.ops;

import com.alibaba.fastjson.JSONObject;
import com.upcode.weighing.util.HttpsUtil;

import static com.upcode.weighing.common.Constants.GENDER_MAN;
import static com.upcode.weighing.common.Constants.GENDER_WOMAN;

/**
 * 相关工具类
 */
public class MapUtils {

    /**
     * 根据地址获取经纬度
     * @param address 地址
     * @return result[0]:经度  result[1]:纬度
     */
    public static String[] getLongLat(String address){
        String url="https://restapi.amap.com/v3/geocode/geo?address="+address+"&output=JSON&key=c21484f46a8c70d96c2156ae529f214f";
        JSONObject jb= HttpsUtil.httpRequest(url,"GET",null);
        String lonLat=jb.getJSONArray("geocodes").getJSONObject(0).getString("location");
        String[] result=lonLat.split(",");
        return result;
    }

    /**
     * 根据身份证获取性别信息
     * @param idCardNo 身份证号码
     * @return result[0]:经度  result[1]:纬度
     */
    public static Integer getGender(String idCardNo){
        int gender = Integer.parseInt(String.valueOf(idCardNo.charAt(idCardNo.length() - 2)));
        if (gender % 2 != 0) {  //男性
            return GENDER_MAN;
        } else {  //女性
            return GENDER_WOMAN;
        }
    }
}
